package com.ruoyi.web.controller.set;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.SetStationAtlas;
import com.ruoyi.system.service.ISetStationAtlasService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 工位-电枪Controller
 *
 * @author ruoyi
 * @date 2022-11-21
 */
@RestController
@Api(tags = "工位-电枪信息")
@RequestMapping("/set/stationAtlas")
public class SetStationAtlasController extends BaseController
{
    @Autowired
    private ISetStationAtlasService setStationAtlasService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询工位-电枪列表
     */
    //@PreAuthorize("@ss.hasPermi('set:stationAtlas:list')")
    @ApiOperation(value = "查询工位-电枪列表")
    @GetMapping("/list")
    public TableDataInfo list(@ApiParam(value = "工位-电枪参数", required = false) SetStationAtlas setStationAtlas)
    {
        startPage();
        List<SetStationAtlas> list = setStationAtlasService.selectSetStationAtlasList(setStationAtlas);
        return getDataTable(list);
    }

    /**
     * 查询工位-电枪下拉接口
     */
    //@PreAuthorize("@ss.hasPermi('set:stationAtlas:interface')")
    @ApiOperation(value = "查询工位-电枪下拉接口")
    @GetMapping("/interface")
    public AjaxResult interfaces(@ApiParam(value = "工位-电枪参数", required = false) SetStationAtlas setStationAtlas)
    {

        List<SetStationAtlas> list = setStationAtlasService.selectSetStationAtlasList(setStationAtlas);
        return AjaxResult.success(list);
    }

    /**
     * 导出工位-电枪列表
     */
    //@PreAuthorize("@ss.hasPermi('set:stationAtlas:export')")
    @Log(title = "工位-电枪", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "导出工位-电枪列表")
    @GetMapping("/export")
    public AjaxResult export(HttpServletResponse response, @ApiParam(value = "工位-电枪参数", required = false) SetStationAtlas setStationAtlas)
    {
        List<SetStationAtlas> list = setStationAtlasService.selectSetStationAtlasList(setStationAtlas);
        ExcelUtil<SetStationAtlas> util = new ExcelUtil<SetStationAtlas>(SetStationAtlas.class);
        return util.exportExcel( list, "工位-电枪数据");
    }

    /**
     * 导入工位-电枪列表
     */
    @Log(title = "工位-电枪", businessType = BusinessType.IMPORT)
    //@PreAuthorize("@ss.hasPermi('set:stationAtlas:import')")
    @ApiOperation(value = "导入工位-电枪列表")
    @PostMapping("/importData")
    public AjaxResult importData(@ApiParam(value = "导入文件", required = true) MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<SetStationAtlas> util = new ExcelUtil<SetStationAtlas>(SetStationAtlas.class);
        List<SetStationAtlas> stationAtlasList = util.importExcel(file.getInputStream());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String operName = loginUser.getUsername();
        String message = setStationAtlasService.importStationAtlas(stationAtlasList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    /**
     * 导入模板
     */
    @ApiOperation(value = "导入模板")
    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        List<SetStationAtlas> list = setStationAtlasService.selectSetStationAtlasList(new SetStationAtlas());
        ExcelUtil<SetStationAtlas> util = new ExcelUtil<SetStationAtlas>(SetStationAtlas.class);
        return util.importTemplateExcel(list,"工位-电枪数据");
    }

    /**
     * 获取工位-电枪详细信息
     */
    //@PreAuthorize("@ss.hasPermi('set:stationAtlas:query')")
    @ApiOperation(value = "获取工位-电枪详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam(value = "工位-电枪id", required = true) @PathVariable("id") Long id)
    {
        return AjaxResult.success(setStationAtlasService.selectSetStationAtlasById(id));
    }

    /**
     * 新增工位-电枪
     */
    //@PreAuthorize("@ss.hasPermi('set:stationAtlas:add')")
    @Log(title = "工位-电枪", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增工位-电枪")
    @PostMapping
    public AjaxResult add(@ApiParam(value = "工位-电枪实体类", required = true) @RequestBody SetStationAtlas setStationAtlas)
    {
        return toAjax(setStationAtlasService.insertSetStationAtlas(setStationAtlas));
    }

    /**
     * 修改工位-电枪
     */
    //@PreAuthorize("@ss.hasPermi('set:stationAtlas:edit')")
    @Log(title = "工位-电枪", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改工位-电枪")
    @PutMapping
    public AjaxResult edit(@ApiParam(value = "工位-电枪实体类", required = true) @RequestBody SetStationAtlas setStationAtlas)
    {
        return toAjax(setStationAtlasService.updateSetStationAtlas(setStationAtlas));
    }

    /**
     * 删除工位-电枪
     */
    //@PreAuthorize("@ss.hasPermi('set:stationAtlas:remove')")
    @Log(title = "工位-电枪", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除工位-电枪")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam(value = "工位-电枪id数组", required = true) @PathVariable Long[] ids)
    {
        return toAjax(setStationAtlasService.deleteSetStationAtlasByIds(ids));
    }
}
